;(function () {
'use strict';
/**
 * user 聂开枥
 * @ngdoc function
 * @name sasdApp.factory:InfoViewService
 * @description 用户管理控制器
 * factory of the sasApp
 */
angular.module('services.resource.cpuResource', [])
  .factory('resourceServer', ['Restangular','dataBaseServer','$filter', resourceServer])
  .factory('dataBaseServer',dataBaseServer)

function resourceServer(Restangular,dataBaseServer,$filter) {
  var messages = {};
  return {
    hosts: function(callback) {
      Restangular.all('sas/OMdisplay/usageRate/host').post({}).then(callback);
    },
    cpus: function(callback) {
      Restangular.all('sas/OMdisplay/usageRate/cpuUsage').post({}).then(callback);
    },
    rams: function(callback) {
      Restangular.all('sas/OMdisplay/usageRate/memoryUsage').post({}).then(callback);
    },
    networks: function(callback) {
      Restangular.all('sas/OMdisplay/usageRate/netUsage').post({}).then(callback);
    },
    disks: function(callback) {
      Restangular.all('sas/OMdisplay/usageRate/discUsage').post({}).then(callback);
    },
    dataBase: function( callback) {
      var param={};
      param=dataBaseServer.param;
      param.startTime= dataBaseServer.param.timeType === '1' ? $filter('date')(dataBaseServer.yearitem.startTime, 'yyyy-MM-dd') : 
                                       $filter('date')(dataBaseServer.yearitem.startTime, 'yyyy-MM-dd HH');
      param.endTime = dataBaseServer.param.timeType=== '1' ? $filter('date')(dataBaseServer.yearitem.endTime, 'yyyy-MM-dd') : 
                                      $filter('date')(dataBaseServer.yearitem.endTime, 'yyyy-MM-dd HH');
      param.regionName=dataBaseServer.param.regionName.length>0 ? dataBaseServer.param.regionName.map(function(item){
         return item.regionName
      }) :[];
      messages=param;

      Restangular.all('sas/OMdisplay/usageRate/dataBase').post(param).then(callback);
    },
    dataBaseDetail: function(callback) {
      Restangular.all('sas/OMdisplay/usageRate/dataBaseDetail').post(messages).then(callback);
    }
  };
}
function dataBaseServer(){
  return{
    param:{
      timeType:'1',
      systemCode:'11',
      regionName:[]
    },
    yearitem:{
      startTime: new Date(new Date().setDate(new Date().getDate() - 4)),
      endTime : new Date()
    }
  }
}
})();